using APP.HELPER.Data.Helper;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Extra.Data
{
    public class xfmCreateDatabase : XtraForm
    {
        private SimpleButton btnCancel;
        private SimpleButton btnLogin;
        private CheckEdit checkEdit1;
        private CheckEdit checkEdit2;
        private CheckEdit checkEdit3;
        private IContainer components = null;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        public TextEdit txtDatabase;
        private ButtonEdit txtPath;

        public event CreateDatabaseEventHander CreateDatabase;

        public xfmCreateDatabase(string connectString)
        {
            this.InitializeComponent();
            SqlHelper.ConnectString = connectString;
            this.txtPath.Text = Application.StartupPath;
            try
            {
                Directory.CreateDirectory(@"D:\Database\Perfect Software\Perfect HRM 2012");
                this.txtPath.Text = @"D:\Database\Perfect Software\Perfect HRM 2012";
            }
            catch (Exception exception)
            {
                XtraMessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.txtDatabase.Text == "")
            {
                XtraMessageBox.Show("Vui l\x00f2ng nhập t\x00ean dữ liệu!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                SqlHelper helper = new SqlHelper();
                if (helper.Exists(this.txtDatabase.Text) != "OK")
                {
                    XtraMessageBox.Show("Cơ sở dữ liệu đ\x00e3 tồn tại!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    base.Hide();
                    this.RaiseCreateDatabaseEventHander(this.txtDatabase.Text, this.txtPath.Text);
                }
            }
        }

        private void btnOrther_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = dialog.SelectedPath;
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmCreateDatabase));
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            this.txtDatabase = new TextEdit();
            this.labelControl5 = new LabelControl();
            this.labelControl4 = new LabelControl();
            this.btnCancel = new SimpleButton();
            this.btnLogin = new SimpleButton();
            this.checkEdit3 = new CheckEdit();
            this.checkEdit2 = new CheckEdit();
            this.checkEdit1 = new CheckEdit();
            this.txtPath = new ButtonEdit();
            this.txtDatabase.Properties.BeginInit();
            this.checkEdit3.Properties.BeginInit();
            this.checkEdit2.Properties.BeginInit();
            this.checkEdit1.Properties.BeginInit();
            this.txtPath.Properties.BeginInit();
            base.SuspendLayout();
            this.txtDatabase.EditValue = "";
            this.txtDatabase.Location = new Point(0x43, 11);
            this.txtDatabase.Name = "txtDatabase";
            this.txtDatabase.Size = new Size(0x149, 20);
            this.txtDatabase.TabIndex = 0x1f;
            this.txtDatabase.KeyDown += new KeyEventHandler(this.txtDatabase_KeyDown);
            this.labelControl5.Location = new Point(7, 0x26);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x37, 13);
            this.labelControl5.TabIndex = 0x22;
            this.labelControl5.Text = "Đường Dẫn";
            this.labelControl4.Location = new Point(7, 14);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x24, 13);
            this.labelControl4.TabIndex = 0x21;
            this.labelControl4.Text = "Dữ Liệu";
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnCancel.Image = (Image)manager.GetObject("btnCancel.Image");
            this.btnCancel.Location = new Point(0x13e, 0x53);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(80, 0x19);
            this.btnCancel.TabIndex = 0x25;
            this.btnCancel.Text = "Đ\x00f3ng";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnLogin.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnLogin.Image = (Image)manager.GetObject("btnLogin.Image");
            this.btnLogin.Location = new Point(0xe8, 0x53);
            this.btnLogin.Name = "btnLogin";
            this.btnLogin.Size = new Size(80, 0x19);
            this.btnLogin.TabIndex = 0x24;
            this.btnLogin.Text = "Thực Hiện";
            this.btnLogin.Click += new EventHandler(this.btnLogin_Click);
            this.checkEdit3.Enabled = false;
            this.checkEdit3.Location = new Point(0x119, 0x3f);
            this.checkEdit3.Name = "checkEdit3";
            this.checkEdit3.Properties.Caption = "Cho ph\x00e9p xuất \x00e2m";
            this.checkEdit3.Size = new Size(0x84, 0x13);
            this.checkEdit3.TabIndex = 0x35;
            this.checkEdit3.Visible = false;
            this.checkEdit2.Enabled = false;
            this.checkEdit2.Location = new Point(0x8f, 0x3f);
            this.checkEdit2.Name = "checkEdit2";
            this.checkEdit2.Properties.Caption = "Quản l\x00fd ph\x00e2n L\x00f4-Serial";
            this.checkEdit2.Size = new Size(0x84, 0x13);
            this.checkEdit2.TabIndex = 0x34;
            this.checkEdit2.Visible = false;
            this.checkEdit1.Enabled = false;
            this.checkEdit1.Location = new Point(5, 0x3f);
            this.checkEdit1.Name = "checkEdit1";
            this.checkEdit1.Properties.Caption = "C\x00f3 dữ liệu tham khảo";
            this.checkEdit1.Size = new Size(0x84, 0x13);
            this.checkEdit1.TabIndex = 0x33;
            this.checkEdit1.Visible = false;
            this.txtPath.Location = new Point(0x43, 0x23);
            this.txtPath.Name = "txtPath";
            this.txtPath.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Glyph, "", -1, true, true, false, ImageLocation.MiddleCenter, (Image)manager.GetObject("txtPath.Properties.Buttons"), new KeyShortcut(Keys.None), appearance, "", null, null, true) });
            this.txtPath.Properties.ReadOnly = true;
            this.txtPath.Properties.ButtonClick += new ButtonPressedEventHandler(this.txtPath_Properties_ButtonClick);
            this.txtPath.Size = new Size(0x149, 0x16);
            this.txtPath.TabIndex = 0x20;
            this.txtPath.TabStop = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x198, 0x73);
            base.Controls.Add(this.checkEdit3);
            base.Controls.Add(this.checkEdit2);
            base.Controls.Add(this.checkEdit1);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnLogin);
            base.Controls.Add(this.txtDatabase);
            base.Controls.Add(this.labelControl5);
            base.Controls.Add(this.labelControl4);
            base.Controls.Add(this.txtPath);
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmCreateDatabase";
            base.ShowIcon = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Tạo Cơ Sở Dữ Liệu";
            base.Load += new EventHandler(this.xfmCreateDatabase_Load);
            this.txtDatabase.Properties.EndInit();
            this.checkEdit3.Properties.EndInit();
            this.checkEdit2.Properties.EndInit();
            this.checkEdit1.Properties.EndInit();
            this.txtPath.Properties.EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                base.Close();
                return true;
            }
            return false;
        }

        private void RaiseCreateDatabaseEventHander(string database, string mPath)
        {
            if (this.CreateDatabase != null)
            {
                this.CreateDatabase(this, database, mPath);
            }
        }

        private void txtDatabase_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btnLogin_Click(this.btnLogin, EventArgs.Empty);
            }
        }

        private void txtPath_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = dialog.SelectedPath;
            }
        }

        private void xfmCreateDatabase_Load(object sender, EventArgs e)
        {
        }

        public delegate void CreateDatabaseEventHander(object sender, string database, string mPath);
    }

}
